package com.accp.jboa.biz;

import com.accp.jboa.dao.LeaveMapper;
import com.accp.jboa.pojo.Check;
import com.accp.jboa.pojo.Leave;
import com.accp.jboa.vo.EmployeeAndDepartmentAndLeaveAndStatus;
import com.accp.jboa.vo.Leaves;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class Leavebiz {

    @Autowired(required = false)
    private LeaveMapper leaveMapper;

    @Autowired(required = false)
    private Checkbiz checkbiz;


    public int insertLeave(Leave leave) {
//        int i = leaveMapper.insertSelective(leave);
//        if (i>0){
//            Check check = new Check();
//            check.setBizid(leave.getLeaveid());
//            check.setTypeid(1);
//            return checkbiz.insertCeck(check).getCheckid();
//        }else {
//            return i;
//        }
        return leaveMapper.insertSelective(leave);
    }

    public PageInfo<Leaves> querybyid(Integer id, Integer page, Integer size, String startTime, String endTime) {
        PageHelper.startPage(page,size);
        if (Objects.equals(startTime, "undefined")){
            startTime = null;
        }
        if (Objects.equals(endTime, "undefined")) {
            endTime = null;
        }
        PageInfo<Leaves> pageInfo = new PageInfo<>(leaveMapper.selectbyid(id,startTime,endTime));
        return pageInfo;
    }

    public Leave queryid(Integer id) {
        return leaveMapper.selectByPrimaryKey(id);
    }

    public int updateLeave(Leave leave) {
        return leaveMapper.updateByPrimaryKeySelective(leave);
    }

    public EmployeeAndDepartmentAndLeaveAndStatus select(Integer id) {
        return leaveMapper.select(id);
    }
}
